This is the first of two examples illustrating the effects of diffusion.
In this example, we will illustrate the homogeneizing effect of intercellular diffusion on the concentrations of species dissolved in cells. We will show that, in the absence of synthesis or degradation, applying diffusion to a tissue with non-uniform initial concentrations results in the uniformization of concentrations throughout the tissue.
In [1]:
%matplotlib notebook
In [2]:
import multicell
import numpy as np
Numpy arrays will be used to define cell-related properties for all cells.
In [3]:
sim = multicell.simulation_builder.generate_cell_grid_sim(20, 1, 1, 1e-3)
In [4]:
sim.register_cell_variable("a")
By default, multicell will consider this variable a as an extensive variable (e.g. a quantity of matter). It will also create an associated intensive variable c_a
. For each cell $c_a = \dfrac{a}{V}$, where V
is the volume of the cell. Therefore, as a
is a quantity of matter, c_a
is a concentration. The names a
and c_a
can be used in equations, as we will see later.
In our example, V
is always 1 (arb. unit), so $c_a = a$.
We also define a single constant D_a
to represent the rate of diffusion of a
.
In [5]:
sim.set_constants({"D_a": 100.})
In Multicell, the differential equations governing cell variables are defined using Python functions following certain conventions.
First, the names of input parameters matter, as they will be used by multicell to map cell properties, constants and computed variables defined in the simulation to the input parameters of differential equations. However, the order of parameters does not matter.
Second, they must return an array (representing a mathematical vector) of values corresponding to the values of each cell, or something that can be broadcast into an array (e.g. a scalar).
We define the differential equation of a
as the following function.
In [6]:
def da_dt(simulation, c_a, D_a, adjacency_matrix):
return simulation.diffusion(D_a, c_a, adjacency_matrix)
sim.set_ODE("a", da_dt)
da_dt
takes four arguments. D_a
is a constant we defined earlier, however the others are automatically managed variables. c_a
is the automatically defined concentration mentioned previously. simulation
is a special name enabling equations to access the Simulation object. adjacency_matrix
is another special name for an automatically generated matrix describing exchange surfaces between cells.
As we only want diffusion, without synthesis or degradation, da_dt
simply returns the effect of diffusion computed by function simulation.diffusion
. In multicell, the effects of transport phenomena (passive or active) should be computed by built-in methods of the Simulation object. This is because these functions do not simply compute the effects of transport, but also expose necessary information to the Simulation object to determine the structure of the Jacobian matrix, which is crucial to the fast integration of the system of differential equations.
Before setting the initial concentrations, we must first signal Multicell that we have finished registering variables, so that the array that will hold the concentrations is created.
In [7]:
sim.initialize_cell_variables()
We then set the initial concentrations to 20 for half of the cells, and 0 for the others, which will have a concentration of 20 (arb. units).
In [8]:
a0 = np.array([20] * 10 + [0] * 10)
sim.set_cell_variable("a", a0)
In [9]:
sim.set_duration(4)
By default, Multicell would only show the final state of the simulation. We would however also like to see some intermediate states, so we set up the simulation to plot results at 10 time points. As diffusive system evolve faster at the beginning of a reaction, we use a log2
spacing of the time points.
In [10]:
sim.set_time_steps(10, "log2")
In [11]:
sim.register_renderer(multicell.rendering.MatplotlibRenderer, "c_a", {"max_cmap": 20, "view": (90, -90), "axes":False})
In [12]:
sim.renderer.display("c_a")
In [13]:
sim.simulate()
All cells now have a concentration close to 10, as shown by the line c_a: from 10.00... to 10.00...
under the plot. This shows that diffusion uniformizes concentrations.